Arithmetic Operations

Simple arithmetic operations, which can be applied as a preliminary step in complex image processing sequences and also as operators in their own right, are applied in a pixel-by-pixel fashion. This means that the value of a pixel in the output image depends only on the values of the corresponding pixels in the input image or images. For example, the result of an addition is that each pixel value in the output dataset is the sum of the values of the corresponding pixel from each of the input images. A main advantage of arithmetic operators is that these processes are very simple and usually quite fast.

The Arithmetic filter allows you to select a number of inputs and then write an expression to produce an output. For example, addition can be used to add components from one image into another image, subtraction can be used for change detection, and multiplication can be used to increase the average gray level of an image by multiplying it with a constant. The convention for identifying each input within an expression is simply "A" for the first dataset, "B" for the second dataset, "C" for the third, and so on. For example, to get the sum of the first dataset and the second dataset, the expression would be "A+B". More complex expressions can also be written, such as "D*[(A+B)+(2*A-1.8*B)]/C.

You can also include NumPy functionalities in an expression. For example, in the expression "np.sin(A)+np.cos(B)", "np.sin" and "np.cos" refer to the "sine" and "cosine" functions of NumPy. NumPy is the fundamental package for scientific computing in Python. At the core of the NumPy package, is the ndarray (N-dimensional array) object, which has a fixed size at creation. NumPy arrays facilitate advanced mathematical and other types of operations on large numbers of data. Typically, such operations are executed more efficiently and with less code than is possible using Python’s built-in sequences.

Unless you choose to work with the Advanced Options, all inputs in arithmetic operations must have the same characteristics — size, location, spacing, orientation and data type— to be used in the same workflow. See Working with the Advanced Options for more information about multi-scale image processing.

To avoid any wrapping of pixel values and for best precision, all calculations for arithmetic operations are done in float. You should note that if you set an output as another data type when working with the Advanced options, all calculations will still be done in float. However, in such cases, the output data values will be rounded and may be clipped.

References

[1] http://www.numpy.org/
[2] http://docs.scipy.org/doc/numpy/